<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%session.setAttribute("username", "蛋蛋");%>
<%session.setAttribute("usernamerole", "蛋蛋");%>
 <script type="text/javascript" src="<%=path%>/myoa/javascripts/jquery-1.11.0.min.js"></script>
 <script src="<%=path%>/myoa/scripts/layui/lay/modules/laydate.js"></script> 
 <script src="<%=path%>/myoa/scripts/layui/layui.js" charset="utf-8"></script>
<script src="<%=path%>/myoa/scripts/js/bootstrap.min.js"></script>
 <link rel="stylesheet" href="<%=path%>/myoa/scripts/css/index.css" />
 <link rel="stylesheet" href="<%=path%>/myoa/scripts/css/bootstrap.min.css" />
 <link rel="stylesheet" href="<%=path%>/myoa/scripts/layui/css/layui.css"  media="all">
<title>会议室管理</title>
</head>
<body>
<div id="content">
 <div>
<a href="#">行政管理</a>>用车管理
</div>
 <hr />
<div class="layui-tab">
  <ul class="layui-tab-title">
    <li class="layui-this">用车申请</li>
    <li>车辆管理</li>
    <li>用车审批</li>
  </ul>
<div class="layui-tab-content">

<!-- 用车申请-->
<div class="layui-tab-item layui-show">
        车辆编号:<select id="quca_carno" style="width:174px">
				<option selected value="">选择车辆</option>
				<option v-for="car in allcars" v-bind:value=car.cm_carno>{{car.cm_carno}}:{{car.cm_style}}</option>
		</select>
		
        开始时间从: <input type='text' id="quca_starttime" class="ctime"/>至
        <input type='text' id="quca_stoptime" class="ctime"/>
        车辆申请状态:
        <select id="quca_applystatus">
       		<option value="">请选择审核状态</option>
        	<option value="待审核">待审核</option>
            <option value="审核成功">审核成功</option>
            <option value="审核失败">审核失败</option>
        </select>
     
        <button type="button" id="but" v-on:click="querycarapply(1)">查询</button>
	<button id="sub">申请</button>
	<div id="querycarapplycontent" style="border-top:1px black solid;border-bottom:1px black solid;">
	<template>
	<p v-if="carapplys.length===0" style="text-align:center">暂无申请信息！</p>

	<table  class="layui-table" v-else>
	<tr id="meetingtitle">
	<th style="text-align:center">序号</th>
	<th style="text-align:center">车辆编号</th>
	<th style="text-align:center">用车开始时间</th>
	<th style="text-align:center">用车结束时间</th>
	<th style="text-align:center">申请人</th>
	<th style="text-align:center">申请状态</th>
	<th style="text-align:center">申请时间</th>
	<th style="text-align:center">操作</th>
	</tr>
	<tr v-for="(car,index) in carapplys">
	<td name="ca_id">
	 {{index+1}}
	</td>
	<td name="ca_carno">{{car.ca_carno}}</td>
	<td name="ca_starttime">{{car.ca_starttime}}</td>
	<td name="ca_stoptime">{{car.ca_stoptime}}</td>
	<td name="ca_applyname">{{car.ca_applyname}}</td>
	<td name="ca_applystatus">{{car.ca_applystatus}}</td>
	<td name="ca_applytime">{{car.ca_applytime}}</td>
	
	<td name="ca_applytime" v-if="car.ca_applystatus=='待审核'"><a href="#" v-on:click="delcarapply($event,car.ca_id)">放弃申请</a></td>
	<td name="ca_applytime" v-else><a href="#" v-on:click="lookcarapply($event,car.ca_id)">查看</a></td>
	</tr></table>
	</template>
	<div id="querycarapplypages"></div>
	</div>
</div>
<!-- 车辆管理 -->
<div class="layui-tab-item">
	<table  class="layui-table" >
	<tr id="cartitle">
	<th style="text-align:center">选择</th>
	<th style="text-align:center">车牌号</th>
	<th style="text-align:center">车型</th>
	<th style="text-align:center">编号</th>
	<th style="text-align:center">状态</th>
	<th style="text-align:center">备注</th>
	<th style="text-align:center">操作</th>
	</tr>
	<tr v-for="car in managecars">
	<td name="cm_id">
	<input type="checkbox" name="selcar" v-bind:value=car.cm_id>
	</td>
	<td name="cm_carid">{{car.cm_carid}}</td>
	<td name="cm_style">{{car.cm_style}}</td>
	<td name="cm_carno">{{car.cm_carno}}</td>
	<td name="cm_carstatus">{{car.cm_carstatus}}</td>
	<td name="cm_remark">{{car.cm_remark}}</td>
	<td style="width:100px">
	<a href="#" id="updatecar" v-on:click="showupdatecarmodel($event,car.cm_id)">修改</a> &nbsp;
	<a href="#" v-on:click="delcar($event,car.cm_id,car.cm_carno)">删除</a>
	</td>
	</tr>
	</table><br/>
	<div id="carpages"></div>
	<button type="button" class="btn btn-primary" data-dismiss="modal" id="addcar">添加车辆</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<button type="button" class="btn btn-primary" data-dismiss="modal" id="delcar" v-on:click="delmeetings($event)">删除车辆</button>
</div>

<!-- 车辆审批 -->
<div class="layui-tab-item">
	        车辆编号:<select id="quca_checkcarno" style="width:174px">
				<option selected value="">选择车辆</option>
				<option v-for="car in allcars" v-bind:value=car.cm_carno>{{car.cm_carno}}:{{car.cm_style}}</option>
		</select>
		
        开始时间从: <input type='text' id="quca_checkstarttime" class="ctime"/>至
        <input type='text' id="quca_checkstoptime" class="ctime"/>
        车辆申请状态:
        <select id="quca_checkapplystatus">
       		<option value="">请选择审核状态</option>
        	<option value="待审核">待审核</option>
            <option value="审核成功">审核成功</option>
            <option value="审核失败">审核失败</option>
        </select>
     
        <button type="button" id="but" v-on:click="queryallcarapply(1)">查询</button>
	<div id="querycarapplycontent" style="border-top:1px black solid;border-bottom:1px black solid;">
	<template>
	<p v-if="querycarapplys.length===0" style="text-align:center">暂无申请信息！</p>

	<table class="layui-table"  v-else>
	<tr id="meetingtitle">
	<th style="text-align:center">序号</th>
	<th style="text-align:center">车辆编号</th>
	<th style="text-align:center">用车开始时间</th>
	<th style="text-align:center">用车结束时间</th>
	<th style="text-align:center">申请人</th>
	<th style="text-align:center">用车人</th>
	<th style="text-align:center">目的地</th>
	<th style="text-align:center">用车是由</th>
	<th style="text-align:center">申请状态</th>
	<th style="text-align:center">申请时间</th>
	
	</tr>
	<tr v-for="(car,index) in querycarapplys">
	<td name="ca_id">
	<input type="hidden" name="selcarapply" v-bind:value=car.ca_id>
	{{index+1}}
	</td>
	<td name="ca_carno"><a v-on:click="checkcarapply()">{{car.ca_carno}}</a></td>
	<td name="ca_starttime">{{car.ca_starttime}}</td>
	<td name="ca_stoptime">{{car.ca_stoptime}}</td>
	<td name="ca_applyname">{{car.ca_applyname}}</td>
	<td name="ca_username">{{car.ca_username}}</td>
	<td name="ca_destination">{{car.ca_destination}}</td>
	<td name="ca_cause">{{car.ca_cause}}</td>
	<td name="ca_applystatus">{{car.ca_applystatus}}</td>
	<td name="ca_applytime">{{car.ca_applytime}}</td>
	</tr></table>
	</template>
	<div id="checkcarapplypages"></div>
	</div>
</div>
</div>
</div>


<!--申请用车弹出层 -->
<div class="modal fade" id="carapply" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header"> 申请用车</div>
                <div class="modal-body">
               <table id="carapplytable" class="layui-table" lay-skin="nob">
					<tr>
					<td>车辆编号：</td>
					<td><select id="ca_carno" name="ma_stype" style="width:174px">
						<option selected value="">选择车辆</option>
					     <option v-for="car in allcars" v-bind:value=car.cm_carno>{{car.cm_carno}}:{{car.cm_style}}</option>
					    </select>
					    <input type="button" value="查看占用情况" v-on:click="checkcar()"/>
					</td>
					</tr>
					<tr>
					<td>申请人：</td>
					<td><input type="text" id="ca_applyname"></td>
					</tr>
					<tr>
					<tr>
					<td>用车人：</td>
					<td><input type="text" id="ca_username"></td>
					</tr>
					<tr>
					<td>开始时间：</td>
					<td><input type='text' id="ca_starttime" class="ctime"/></td>
					</tr>
					<tr>
					<td>结束时间：</td>
					<td><input type='text' id="ca_stoptime" class="ctime" /></td>
					</tr>
					<tr>
					<td>目的地：</td>
					<td><input type="text" id="ca_destination"></td>
					</tr>
					<tr>
					<td>用车事由：</td>
					<td><textarea style="width:300px;height:100px;max-width:300px;max-height:100px" id="ca_cause"></textarea></td>
					</tr>
					</table> 
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary" data-dismiss="modal" id="addcarsubmit" v-on:click="carapply()">申请</button>
                </div>
            </div>
        </div>
    </div>
    <!--审批用车弹出层 -->
<div class="modal fade" id="checkcarapply" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">用车审批</div>
                <div class="modal-body">
               <table id="carapplytable" class="layui-table"  >
					<tr>
					<td>车辆编号：</td>
					<td>
					<span id="check_carno"></span> 
					<input type="button" value="查看占用情况" v-on:click="checkcar1()"/>
					<input type="hidden" id="check_id"/>
					</td>
					</tr>
					<tr>
					<td>申请人：</td>
					<td id="check_applyname"></td>
					</tr>
					<tr>
					<tr>
					<td>用车人：</td>
					<td id="check_username"></td>
					</tr>
					<tr>
					<td>开始时间：</td>
					<td id="check_starttime"></td>
					</tr>
					<tr>
					<td>结束时间：</td>
					<td id="check_stoptime"></td>
					</tr>
					<tr>
					<td>目的地：</td>
					<td id="check_destination"></td>
					</tr>
					<tr>
					<td>申请时间：</td>
					<td id="check_applytime"></td>
					</tr>
					<tr>
					<td>用车事由：</td>
					<td><textarea id="check_cause" readonly style="min-width:400px;min-height:100px;max-width:400px;max-height:100px;"></textarea></td>
					</tr>
					<tr>
					<td>申请意见：</td>
					<td id="check_applystatus">同意：<input type="radio" name="status" value="审核通过"/> &nbsp;&nbsp;不同意：<input type="radio" name="status" value="审核失败"/></td>
					</tr>
					</table> 
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary" data-dismiss="modal" id="addcarsubmit" v-on:click="updatecarapply()">提交</button>
                </div>
            </div>
        </div>
    </div>
     <!--查看申请弹出层 -->
<div class="modal fade" id="lookcarapply" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">申请详情</div>
                <div class="modal-body">
               <table id="carapplytable" class="layui-table" >
					<tr>
					<td>车辆编号：</td>
					<td>
					<span id="look_carno">{{lookcar.ca_carno}} </span>
					</td>
					</tr>
					<tr>
					<td>申请人：</td>
					<td><span id="look_applyname">{{lookcar.ca_applyname}}</span></td>
					</tr>
					<tr>
					<tr>
					<td>用车人：</td>
					<td><span id="look_username">{{lookcar.ca_username}}</span></td>
					</tr>
					<tr>
					<td>开始时间：</td>
					<td><span id="look_starttime">{{lookcar.ca_starttime}}</span></td>
					</tr>
					<tr>
					<td>结束时间：</td>
					<td><span id="look_stoptime">{{lookcar.ca_stoptime}}</span></td>
					</tr>
					<tr>
					<td>目的地：</td>
					<td><span id="look_destination">{{lookcar.ca_destination}}</span></td>
					</tr>
					<tr>
					<td>申请时间：</td>
					<td><span id="look_applytime">{{lookcar.ca_applytime}}</span></td>
					</tr>
					<tr>
					<td>用车事由：</td>
					<td><textarea id="look_cause" readonly style="min-width:400px;min-height:100px;max-width:400px;max-height:100px;">{{lookcar.ca_cause}}</textarea></td>
					</tr>
					<tr>
					<td>申请意见：</td>
					<td><span id="look_applystatus">{{lookcar.ca_applystatus}}</span></td>
					</tr>
					
					</table> 
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
<!-- 修改车辆弹出层 -->
<div class="modal fade" id="updatecars" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header"> 修改车辆信息</div>
                <div class="modal-body">
                 <table id="carapplytable" class="layui-table" >
						<tr>
						<td>车牌号：</td>
						<input type="hidden" id="updateid" name="cm_id" readonly />
						<td><input type="text" id="updatecarid" name="cm_carid" readonly></td>
						</tr>
						<tr>
						<td>车型：</td>
						<td><input type="text" id="updatestyle" name="cm_style" readonly></td>
						</tr>
						<tr>
						<td>车辆编号：</td>
						<td><input type="text" id="updatecarno" name="cm_carno" readonly></td>
						</tr>
						<tr>
						<td>车辆状态：</td>
						<td>
						<select id="updatecarstatus" name="cm_carstatus">
				            <option selected value="正常">正常</option>
				            <option value="维修中">维修中</option>
				          </select>
				         </td>
						</tr>
						<tr>
						<td>备注：</td>
						<td><textarea style="width:300px;height:100px;max-width:300px;max-height:100px"  id="updateremark" name="cm_remark"></textarea></td>
						</tr>
					</table>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" data-dismiss="modal" id="carupdatesubmit" v-on:click="updatecar()">提交</button>
                </div>
            </div>
        </div>
    </div>
<!-- 新增车辆弹出层 -->
<div class="modal fade" id="add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header"> 新增车辆</div>
                <div class="modal-body">
               <form action="" id="caraddform">
                 <table class="layui-table">
						<tr>
						<td>车牌号：</td>
						<td><input type="text" id="addcarid" name="cm_carid"></td>
						</tr>
						<tr>
						<td>车型：</td>
						<td><input type="text" id="addcarstyle" name="cm_style"></td>
						</tr>
						<tr>
						<td>车辆编号：</td>
						<td><input type="text" id="addcarno" name="cm_carno"></td>
						</tr>
						<tr>
						<td>车辆状态：</td>
						<td>
						<select id="addcarstatus" name="cm_carstatus">
				            <option selected value="正常">正常</option>
				            <option value="维修中">维修中</option>
				          </select>
				         </td>
						</tr>
						<tr>
						<td>备注：</td>
						<td><textarea style="width:300px;height:100px;max-width:300px;max-height:100px" id="addcarremark" name="cm_remark"></textarea></td>
						</tr>
					</table>
					</form>				     
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary" data-dismiss="modal" id="addcarsubmit" v-on:click="addcar()">提交</button>
                </div>
            </div>
        </div>
    </div>

</div>
</body>
<script src="scripts/js/vue.js"></script>
<script type="text/javascript">
$(function(){
var vm = new Vue({
            el: "#content",
            data: {
               managecars:[],
               allcars:[],
               carapplys:[],
               querycarapplys:[],
             lookcar:[],
            },
			methods:{
				//添加车辆
				addcar:function(){
					var cm_id=$("#addcarid").val();
					var cm_style=$("#addcarstyle").val();
					var cm_carno=$("#addcarno").val();
					var cm_carstatus=$("#addcarstatus").val();
					var cm_remark=$("#addcarremark").val();
					console.log("cmid="+cm_id+"cm_style="+cm_style+"cm_carno="+cm_carno+"cm_remark="+cm_remark)
					$.ajax({
					url:"<%=path%>/addcar",
					data:{cm_carid:cm_id,cm_style:cm_style,cm_carno:cm_carno,cm_carstatus:cm_carstatus,cm_remark:cm_remark},
					type:"post",
					dataType:"json",
					success:function(result){
						if(result!=0){
							alert("添加成功")
							location.reload();
						}
					}
				})
				},
				//修改车辆状态模态框触发事件
				showupdatecarmodel:function(event,cm_id){
					var el = event.currentTarget;
					$("#updatecars").modal("show");
	      			var cm_carid=$(el).parent().siblings("td[name='cm_carid']").html();
	      			var cm_style=$(el).parent().siblings("td[name='cm_style']").html();
	      			var cm_carno=$(el).parent().siblings("td[name='cm_carno']").html();
	      			var cm_remark=$(el).parent().siblings("td[name='cm_remark']").text();
	      			$("#updateid").val(cm_id);
	      			$("#updatecarid").val(cm_carid);
	      			$("#updatestyle").val(cm_style);
	      			$("#updatecarno").val(cm_carno);
	      			$("#updateremark").val(cm_remark);
	      			console.log("cm_id="+cm_id+"cm_carid="+cm_carid+"cm_remark="+cm_remark)	
				},
			//查询车辆
			SearchCar:function(curr){
				var _self = this;
				$.ajax({
				url:"<%=path%>/querycar",
				data:{curr:curr,pagesize:4},
				type:"post",
				dataType:"json",
				success:function(result){
					console.log(result.allcmlist)
					_self.managecars=result.cmlist;
					_self.allcars=result.allcmlist;
					//分页插件
				       layui.use(['laypage', 'layer'], function(){
				    	   var laypage = layui.laypage
				    	   ,layer = layui.layer;
				    	   
				    	   //总页数低于页码总数
				    	   laypage.render({
				    	     elem: 'carpages'
				    	     ,count: result.totle //数据总数
				    	     ,limit:4
				    	    ,curr:curr
				    	   , layout: ['count', 'prev', 'page', 'next', 'skip']
				    	     ,jump: function(obj, first){
				    	         if(!first){
				    	        	 vm.SearchCar(obj.curr)
				    	         }
				    	       }
				    	   })
				       });
				}
			})
			},
			//修改车辆
				updatecar:function(){
					var cm_id=$("#updateid").val();
					var cm_carstatus=$("#updatecarstatus").val();
					var cm_remark=$("#updateremark").val();
					console.log("cmid="+cm_id+"cm_carstatus="+cm_carstatus+"cm_remark="+cm_remark)
					$.ajax({
					url:"../updatecar",
					data:{cm_id:cm_id,cm_carstatus:cm_carstatus,cm_remark:cm_remark},
					type:"post",
					dataType:"json",
					success:function(result){
						if(result!=0){
							alert("添加成功")
							location.reload();
						}
					}
				})
				},
				//删除申请
				delcarapply:function(event,ca_id){
					var r=confirm("确定删除该申请吗？")
					if(r==true){
						$.ajax({
							url:"../delcarapply",
							data:{ca_id:ca_id},
							type:"post",
							dataType:"json",
							success:function(result){
								if(result!=0){
									alert("删除成功！")
									location.reload();
								}
							}
						})
						return
					}else{
						return
					}
				},
				//删除车辆
				delcar:function(event,cm_id,cm_carno){
					var el = event.currentTarget;
					var cm_ids=cm_id+",";
					console.log("cmids="+cm_ids)	
					$.ajax({
							url:"../checkcar",
							data:{ca_carno:cm_carno},
							type:"post",
							dataType:"json",
							success:function(result){
								if(result.ck2=="维修中"){
									alert("该车正在维修,暂不能删除")
									return
								}if(result.ck2=="正常"){
									if(result.ck1==null){
										$.ajax({
											url:"../delcar",
											data:{cm_ids:cm_ids},
											type:"post",
											dataType:"json",
											success:function(result){
												if(result!=0){
													alert("删除成功")
													location.reload();
												}
											}
										})
										return
									}if(result.ck1!=null){
										alert("该车正在使用,暂不能删除")
										return
									}
								}
								console.log(result)
							}
						})
				},
				//批量删除车辆
				delmeetings:function(){
					var el = event.currentTarget;
					var cmids=""
					$(el).parent().find("input[name='selcar']:checked").each(function (index, item){
						cmids=cmids+$(item).val() + ","
					})
						console.log(cmids)
					if(cmids==""){
						alert("请选择要删除的车辆哟");
						return;
					}else{
						$.ajax({
							url:"../delcar",
							data:{cm_ids:cmids},
							type:"post",
							dataType:"json",
							success:function(result){
								console.log(result);
								if(result!=0){
									alert("删除成功")
									location.reload();
								}
							}
						})
					}
				},
				//查看车辆占用情况
				checkcar:function(){
					var ca_starttime=$("#ca_starttime").val();
					var ca_stoptime=$("#ca_stoptime").val();
					var ca_carno=$("#ca_carno option:selected").val();
					console.log(ca_carno)
					var _self = this;
					if(ca_carno==""){
						alert("请输入查询的车辆")
						return
					}
					if(ca_starttime==""){
						alert("请输入查询的起始时间")
						return
					}if(ca_stoptime==""){
						alert("请输入查询的起始时间")
						return
					}else{
						console.log("ca_carno"+ca_carno+"ca_starttime"+ca_starttime+"ca_stoptime"+ca_stoptime)
						$.ajax({
							url:"../checkcar",
							data:{ca_carno:ca_carno,ca_starttime:ca_starttime,ca_stoptime:ca_stoptime,},
							type:"post",
							dataType:"json",
							success:function(result){
								if(result.ck2=="维修中"){
									alert("该车正在维修")
									return
								}if(result.ck2=="正常"){
									if(result.ck1==null){
										alert("该车可以使用")
										return
									}if(result.ck1!=null){
										alert("该车已被租用")
										return
									}
								}
								
								console.log(result)
							}
						})
					}
				},
				//审批时查询车辆占用情况
				checkcar1:function(){
					var ca_starttime=$("#check_starttime").html();
					var ca_stoptime=$("#check_stoptime").html();
					var ca_carno=$("#check_carno").html();
					console.log(ca_carno)
					var _self = this;
						console.log("ca_carno"+ca_carno+"ca_starttime"+ca_starttime+"ca_stoptime"+ca_stoptime)
						$.ajax({
							url:"../checkcar",
							data:{ca_carno:ca_carno,ca_starttime:ca_starttime,ca_stoptime:ca_stoptime,},
							type:"post",
							dataType:"json",
							success:function(result){
								if(result.ck2=="维修中"){
									alert("该车正在维修")
									return
								}if(result.ck2=="正常"){
									if(result.ck1==null){
										alert("该车可以使用")
										return
									}if(result.ck1!=null){
										alert("该车已被租用")
										return
									}
								}
								
								console.log(result)
							}
						})
					
				},
				//审批用车
				updatecarapply:function(){
					var ca_id=$("#check_id").val();
					var ca_applystatus=$("#check_applystatus").find("input[name='status']:checked").val();
					console.log("ca_id="+ca_id+"ca_applystatus="+ca_applystatus)	
					$.ajax({
					url:"../updatecarapply",
					data:{ca_id:ca_id,ca_applystatus:ca_applystatus},
					type:"post",
					dataType:"json",
					success:function(result){
						if(result!=0){
							alert("操作成功")
							location.reload();
						}
					}
				})
				},
				//申请用车
				carapply:function(){
					var ca_carno=$("#ca_carno option:selected").val();
					var ca_applyname=$("#ca_applyname").val();
					var ca_username=$("#ca_username").val();
					var ca_starttime=$("#ca_starttime").val();
					var ca_stoptime=$("#ca_stoptime").val();
					var ca_destination=$("#ca_destination").val();
					var ca_cause=$("#ca_cause").val();
					var ca_driver=$("#ca_driver option:selected").val();
					console.log("ca_carno="+ca_carno+"ca_applyname="+ca_applyname+"ca_username="+ca_username+
							"ca_starttime="+ca_starttime+"ca_stoptime="+ca_stoptime+"ca_destination="+ca_destination
							+"ca_cause="+ca_cause+"ca_driver="+ca_driver)
					if(ca_carno==null||ca_carno==""){
			            alert("请选择车辆")
			            return
			           }
			        if(ca_applyname==null||ca_applyname==""){
			            alert("请输入您的名字")
			            return
			           }
			        if(ca_username==null||ca_username==""){
			            alert("请输入用车人姓名")
			            return
			          }
			        if(ca_starttime==null||ca_starttime==""){
			            alert("请输入用车开始时间")
			            return
			            }
			        if(ca_stoptime==null||ca_stoptime==""){
			           alert("请输入用车结束时间")
			            return
			          }
			        if(ca_destination==null||ca_destination==""){
			            alert("请输入目的地")
			            return
			          }
			        if(ca_cause==null||ca_cause==""){
			            alert("请输入用车是由")
			            return
			            }
			        if(ca_driver==null||ca_driver==""){
			           alert("请输入下一步审核人")
			            return
			          }else{
			        	  $.ajax({//判断用车时间是否冲突
								url:"../checkcar",
								data:{ca_carno:ca_carno,ca_starttime:ca_starttime,ca_stoptime:ca_stoptime,},
								type:"post",
								dataType:"json",
								success:function(result){
									if(result.ck2=="维修中"){
										alert("该车正在维修")
										return
									}if(result.ck2=="正常"){
										if(result.ck1==null){//如果不冲突，则添加到数据库
											$.ajax({
												url:"../carapply",
												data:{ca_carno:ca_carno,ca_applyname:ca_applyname,ca_username:ca_username,ca_starttime:ca_starttime,
													ca_stoptime:ca_stoptime,ca_destination:ca_destination,ca_cause:ca_cause,ca_driver:ca_driver},
												type:"post",
												dataType:"json",
												success:function(result){
													if(result!=0){
														alert("申请成功")
														location.reload();
													}
												}
											})
											return
										}if(result.ck1!=null){
											alert("该车已被租用")
											return
										}
									}
									console.log(result)
								}
							})
			          }
				},
				//查询申请的车辆
				querycarapply:function(curr){
					var quca_carno=$("#quca_carno option:selected").val();
					var quca_starttime=$("#quca_starttime").val();
					var quca_stoptime=$("#quca_stoptime").val();
					var quca_applystatus=$("#quca_applystatus option:selected").val();
					console.log("quca_carno="+quca_carno+"quca_starttime="+quca_starttime+"quca_stoptime="+quca_stoptime+"quca_applystatus="+quca_applystatus)
					var _self = this;
					$.ajax({
					url:"../querycarapply",
					data:{curr:curr,pagesize:4,ca_carno:quca_carno,ca_starttime:quca_starttime,ca_stoptime:quca_stoptime,ca_applystatus:quca_applystatus},
					type:"post",
					dataType:"json",
					success:function(result){
						_self.carapplys=result.querycarapplylist
						console.log(_self.carapplys)
						//分页插件
					       layui.use(['laypage', 'layer'], function(){
					    	   var laypage = layui.laypage
					    	   ,layer = layui.layer;
					    	   
					    	   //总页数低于页码总数
					    	   laypage.render({
					    	     elem: 'querycarapplypages'
					    	     ,count: result.totle //数据总数
					    	     ,limit:4
					    	    ,curr:curr
					    	   , layout: ['count', 'prev', 'page', 'next', 'skip']
					    	     ,jump: function(obj, first){
					    	         if(!first){
					    	        	 vm.querycarapply(obj.curr)
					    	         }
					    	       }
					    	   })
					       });
					}
				})
				},
				//审批时查询申请的车辆
				queryallcarapply:function(curr){
					var quca_carno=$("#quca_checkcarno option:selected").val();
					var quca_starttime=$("#quca_checkstarttime").val();
					var quca_stoptime=$("#quca_checkstoptime").val();
					var quca_applystatus=$("#quca_checkapplystatus option:selected").val();
					console.log("quca_carno="+quca_carno+"quca_starttime="+quca_starttime+"quca_stoptime="+quca_stoptime+"quca_applystatus="+quca_applystatus)
					var _self = this;
					$.ajax({
					url:"../querycheckcarapply",
					data:{curr:curr,pagesize:4,ca_carno:quca_carno,ca_starttime:quca_starttime,ca_stoptime:quca_stoptime,ca_applystatus:quca_applystatus},
					type:"post",
					dataType:"json",
					success:function(result){
						_self.querycarapplys=result.querycarchecklist
						//分页插件
					       layui.use(['laypage', 'layer'], function(){
					    	   var laypage = layui.laypage
					    	   ,layer = layui.layer;
					    	   
					    	   //总页数低于页码总数
					    	   laypage.render({
					    	     elem: 'checkcarapplypages'
					    	     ,count: result.totle //数据总数
					    	     ,limit:4
					    	    ,curr:curr
					    	   , layout: ['count', 'prev', 'page', 'next', 'skip']
					    	     ,jump: function(obj, first){
					    	         if(!first){
					    	        	 vm.queryallcarapply(obj.curr)
					    	         }
					    	       }
					    	   })
					       });
					}
				})
				},
				//审批车辆模态框触发事件
				checkcarapply:function(){
					var el = event.currentTarget;
					$("#checkcarapply").modal("show");
					var ca_id=$(el).parent().siblings("td[name='ca_id']").find("input[type='hidden']").val();
	      	   		var ca_carno=$(el).html();
	      			var ca_starttime=$(el).parent().siblings("td[name='ca_starttime']").html();
	      			var ca_stoptime=$(el).parent().siblings("td[name='ca_stoptime']").html();
	      			var ca_applyname=$(el).parent().siblings("td[name='ca_applyname']").html();
	      			var ca_applytime=$(el).parent().siblings("td[name='ca_applytime']").html();
	      			var ca_username=$(el).parent().siblings("td[name='ca_username']").html();
	      			var ca_cause=$(el).parent().siblings("td[name='ca_cause']").html();
	      			var ca_destination=$(el).parent().siblings("td[name='ca_destination']").html();
	      			$("#check_id").val(ca_id);
	      			$("#check_carno").html(ca_carno);
	      			$("#check_applyname").html(ca_applyname);
	      			$("#check_username").html(ca_username);
	      			$("#check_starttime").html(ca_starttime);
	      			$("#check_stoptime").html(ca_stoptime);
	      			$("#check_applytime").html(ca_applytime);
	      			$("#check_destination").html(ca_destination);
	      			$("#check_cause").html(ca_cause);
				},
				//查看申请详情
				lookcarapply:function(event,ca_id){
					var el = event.currentTarget;
					console.log("++++"+ca_id)
					
					 $.ajax({
						url:"../querylookcarapply",
						data:{ca_id:ca_id},
						type:"post",
						dataType:"json",
						success:function(result){
							console.log("申请详情"+result)
							vm.lookcar=result
							$("#lookcarapply").modal("show");
						} 
					 }) 
					
				},
			}
        });
    vm.SearchCar(1),
    vm.querycarapply(1),
    vm.queryallcarapply(1), 
//新增车辆模态框触发事件    
$("#addcar").click(function(){
           $("#add").modal("show");
        });
//申请车辆模态框触发事件     
$("#sub").click(function(){
     	$("#carapply").modal("show");
     })
   
//时间插件
lay('.ctime').each(function(){
       laydate.render({
    	   elem: this
    	   ,type: 'datetime'
    	   ,trigger: 'click'
    	   ,format:'yyyy年M月d日H时m分'
    	 })
       });
});    
layui.use('element', function(){
    	   var $ = layui.jquery
    	   ,element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
    	   //触发事件
    	   var active = {
    	   tabChange: function(){
    	       //切换到指定Tab项
    	       element.tabChange('demo', '22'); //切换到：用户管理
    	     }
    	   };
    	   $('.site-demo-active').on('click', function(){
    	     var othis = $(this), type = othis.data('type');
    	     active[type] ? active[type].call(this, othis) : '';
    	   });
    	 });
       
</script>

</html>